package com.tiemei.demo.unittest.mockito;

import java.util.LinkedList;
import java.util.List;
import static org.mockito.Mockito.*;

import org.junit.Test;

/**
 * 类似anyInt() eq() ....
 * 
 * 注意：
 * 若方法中的某一个参数使用了matcher，则所有的参数都必须使用matcher
 * <pre>
 *  // correct  
    verify(mock).someMethod(anyInt(), anyString(), eq("third argument"));  
    // will throw exception  
    verify(mock).someMethod(anyInt(), anyString(), "third argument");
 * </pre>
 * @author tiemei.jdk
 * @date   2012-10-15
 */
public class ArgumentMatchers {
	@Test
	public void testArgumentMatchers () {
		// 1. mock
		List mockedList = mock(LinkedList.class);
		// stubbing using built-in anyInt() argument matcher  
		when(mockedList.get(anyInt())).thenReturn("element");  
		
		// 2. run
		// following prints "element"  
		System.out.println(mockedList.get(999));  
		  
		// 3. verify
		// you can also verify using an argument matcher  
		verify(mockedList).get(anyInt());  
	}
}
